package com.bst.bsj.portal.util;

import java.io.UnsupportedEncodingException;

import com.alibaba.fastjson.JSON;

public class JsonSerializable {

    public Object deserialize(byte[] bytes) {
        try {
            return JSON.parse(new String(bytes, "GBK"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return null;
    }

    public byte[] serialize(Object obj) {
        JsonProtocol protocol = new JsonProtocol();
        protocol.setCode("200");
        protocol.setData(obj);
        byte[] bytes = JSON.toJSONBytes(protocol);
        return bytes;
    }
    
    public byte[] serialize(String code,Object obj) {
        JsonProtocol protocol = new JsonProtocol();
        protocol.setCode(code);
        protocol.setData(obj);
        byte[] bytes = JSON.toJSONBytes(protocol);
        return bytes;
    }
}
